﻿#region License
/***********************************************
 *  SearchEF v.1
 *  Written by James Levingston
 *  
 *  To get latest version or to see latest info:
 *  http://searchef.codeplex.com/
 *  
 *  The MIT License (MIT)
 *  http://en.wikipedia.org/wiki/MIT_License
 *  Copyright (C) <2011> by <James Levingston>
 *
 *  Permission is hereby granted, free of charge, to any person obtaining a copy
 *  of this software and associated documentation files (the "Software"), to deal
 *  in the Software without restriction, including without limitation the rights
 *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *  copies of the Software, and to permit persons to whom the Software is
 *  furnished to do so, subject to the following conditions:
 *
 *  The above copyright notice and this permission notice shall be included in
 *  all copies or substantial portions of the Software.

 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 *  THE SOFTWARE.
 ***/
#endregion

using System;
using System.Collections.Generic;

namespace SearchEF
{
    public interface ISearchResult
    {
        /// <summary>
        /// Result Type instance
        /// </summary>
        object ResultObject { get; set; }
        /// <summary>
        /// Type of Result
        /// </summary>
        Type ResultType { get; set; }
        /// <summary>
        /// Content of the Entity
        /// </summary>
        string Content { get; set; }
        /// <summary>
        /// Correlation of the result
        /// </summary>
        MatchCorrelation Correlation { get; set; }
        /// <summary>
        /// Operand that located the result
        /// </summary>
        SearchOperatorEnum OperatorType { get; set; }
        /// <summary>
        /// Search pattern used to find the result
        /// </summary>
        string Operand { get; set; }
    }
    /// <summary>
    /// Information returned from a search result
    /// </summary>
    public interface ISearchResult<T> : ISearchResult where T : class
    {
        /// <summary>
        /// Result Type instance
        /// </summary>
        T Value { get; }
    }
    /// <summary>
    /// Concrete type for ISearchResult
    /// Contains the details of a LINQ search engine result
    /// </summary>
    public class SearchResult<T> : ISearchResult<T> where T : class
    {
        public object ResultObject { get; set; }
        public T Value { get { return this.ResultObject as T; } }
        public Type ResultType { get; set; }
        public string Content { get; set; }
        public MatchCorrelation Correlation { get; set; }
        public SearchOperatorEnum OperatorType { get; set; }
        public string Operand { get; set; }
    }
    /// <summary>
    /// Values that define how the result is correlated to the content
    /// </summary>
    public enum MatchCorrelation
    {
        /// <summary>
        /// One exact match - 100 correlated
        /// </summary>
        Exact = 100,
        /// <summary>
        /// 25 or less matches on the content - 75% correlated
        /// </summary>
        High = 75,
        /// <summary>
        /// 25 to 50 matches on the content - 50% correlated
        /// </summary>
        Medium = 50,
        /// <summary>
        /// 50 or more matches on the content - 25% correlated
        /// </summary>
        Low = 25,
        /// <summary>
        /// No matches
        /// </summary>
        Zero = 0,
        /// <summary>
        /// Unknown correlation
        /// </summary>
        Unknown = -1
    }

    /// <summary>
    /// Class defines a logical operand
    /// Used when processing the stack
    /// </summary>
    public class SearchOperand
    {
        public string Operand { get; set; }
        public SearchOperatorEnum OperatorType { get; set; }
    }
    /// <summary>
    /// Logical operands supported
    /// </summary>
    public enum SearchOperatorEnum
    {
        NOT = 0,
        AND = 1,
        OR = 2
    }
}
